class SingletonMeta(type):
    _instances = {}  # 存储类的实例

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super().__call__(*args, **kwargs)
        return cls._instances[cls]

class SingletonBase(metaclass=SingletonMeta):
    pass

if __name__=='__main__':
    # 任何继承自SingletonBase的类都会自动成为单例
    class MyClass(SingletonBase):
        def __init__(self, name):
            self.name = name
    
    # 使用示例
    a = MyClass("Kimi")
    b = MyClass("Moonshot")

    print(a is b)  # 输出: True，表明a和b是同一个实例
    print(a.name, b.name)  # 输出: Kimi Kimi，表明它们共享状态